home *** CD-ROM | disk | FTP | other *** search
- /*
- Library for ftpd clients.(libftp)
- Copyright by Oleg Orel
- All rights reserved.
-
- This library is desined for free, non-commercial software creation.
- It is changeable and can be improved. The author would greatly appreciate
- any advises, new components and patches of the existing programs.
- Commercial usage is also possible with participation of it's author.
-
-
-
- */
-
- #include "FtpLibrary.h"
-
- STATUS FtpConnect(FTP **con,char * hostname)
- {
- struct sockaddr_in unit;
- register struct hostent *host;
- register struct servent *service;
- register int sock;
- String S1;
- STATUS x;
-
- *con = ( FTP * ) malloc ( sizeof (FTP));
-
- if ((host=FtpGetHost(hostname))==NULL)
- return EXIT((*con),QUIT);
- if ((service=(struct servent *) getservbyname("ftp","tcp"))==0)
- return EXIT((*con),QUIT);
-
- unit.sin_family = host -> h_addrtype;
-
- bcopy(host-> h_addr_list[0],(char *)&unit.sin_addr,host->h_length);
- if ( ( sock = socket ( unit.sin_family , SOCK_STREAM , 0)) < 0)
- return EXIT((*con),QUIT);
-
- unit.sin_port = service -> s_port;
-
- while ( connect ( sock , &unit , sizeof unit ) < 0 )
- {
- host -> h_addr_list ++;
- if (host -> h_addr_list[0]==NULL) {
- close(sock);
- return EXIT((*con),QUIT);
- }
- bcopy(host -> h_addr_list[0],(char *)&unit,host->h_length);
- close(sock);
- if ( ( sock = socket ( unit.sin_family , SOCK_STREAM , 0)) < 0)
- {
- close(sock);
- return EXIT((*con),QUIT);
- }
- }
-
- (*con) -> sock = sock;
- (*con) -> mode = 'A';
- (*con) -> data = 0;
- (*con) -> func = NULL;
- (*con) -> debug = NULL;
-
- if (ftplib_debug) FtpDebug(*con);
-
- if ( (x=FtpGetMessage(*con,S1)) == QUIT )
- return EXIT((*con),QUIT);
- if ( ! FtpGood(x,120,220,EOF))
- {
- close(sock);
- return EXIT((*con),-x);
- }
- return EXIT((*con),x);
- }
-
-
-
-